define(function() {
	return function($compile, $scope) {
		require(
				[ "AppPathDir/product/searchProductForSelfInfos/support",
						"PDUtilDir/inputSelect", "Date", "DateCN",
						"css!DateCss",
						"css!AppPathDir/product/searchProductInfos/views/css/css" ],
				function(Support, inputSelect) {
					/* 查询 start */
					$scope.search = {}
					$scope.cache = {
						saleStatus: new Array(),
						types: new Array()
					}
					$scope.searchSupport = {
						run : function() {
							$scope.grid.reload({
								queryParam : {
									model : JSON.stringify($scope.search)
								}
							})
						}
					};
					$scope.detailSupport = {
						run : function(data) {
							window.top.tabs
									.addTab({
										id : data.id,
										title : "【" +data.name + "】预定",
										remote : {
											url : getServer()
													+ "/static/core/page/home/subHome.jsp",
											iframe : true,
											param : {
												html : getServer()
                                                	+ "/static/app/product/searchProductInfos/views/detail.html",
														// + "/static/app/product/searchProductForSelfInfos/views/detail.html",
												ctrl : getServer()
														+ "/static/app/product/searchProductInfos/detailSupport.js",
                                            // + "/static/app/product/searchProductForSelfInfos/detailSupport.js",
												id : data.id
											}
										}
									});
						}
					};
					// 产品类别
					$.ajax({
						url : getServer() + "/flea/hclv/getTourism.htmls",
						success : function(data) {
							$scope.cache.types = data.data;
							$scope.renderGridFun();
						}
					});
					// 省
					$.ajax({
						url : getServer() + "/flea/hclv/getProvinces.htmls",
						success : function(data) {
							$scope.cache.provinces = data.data;
							init_startPlaceProvince();
							init_endPlaceProvince();
						}
					});
					// 销售状态
					$.ajax({
						url : getServer() + "/flea/hclv/getSaleStatus.htmls",
						success : function(data) {
							$scope.cache.saleStatus = data.data;
							init_saleStatus();
							$scope.renderGridFun();
						}
					});

					$scope.getCity = function(type, pcode) {
						$.ajax({
							url : getServer() + "/flea/hclv/getCity.htmls",
							data : {
								'pcode' : pcode
							},
							success : function(data) {
								var citys = data.data;
								if (type == "start") {
									$scope.cache.startPlaceCity = data.data;
									init_startPlaceCity();
								} else {
									$scope.cache.endPlaceCity = data.data;
									init_endPalceCity();
								}
							}
						});
					};
					var init_startPlaceProvince = function() {
						// 初始化下拉框
						inputSelect.dropCache();
						inputSelect({
							id : "startPlaceProvince",
							key : {
								id : "dictCode",
								name : "dictName",
								data : "data",
							},
							data : $scope.cache.provinces,
							simpleData : true,
							// 启用文本搜索
							// initData:[initProvice],
							searchAble : false,
							callback : function(id) {
								var id = id[0];
								$scope.search.startPlaceProvince = id;
								$scope.getCity('start', id);
							}
						});
					}, init_startPlaceCity = function() {
						// 初始化下拉框
						inputSelect.dropCache();
						inputSelect({
							id : "startPlaceCity",
							key : {
								id : "dictCode",
								name : "dictName",
								data : "data",
							},
							data : $scope.cache.startPlaceCity,
							simpleData : true,
							// 启用文本搜索
							// initData:[initProvice],
							searchAble : false,
							callback : function(id) {
								var id = id[0];
								$scope.search.startPlaceCity = id;
							}
						});
					}, init_endPlaceProvince = function() {
						// 初始化下拉框
						inputSelect.dropCache();
						inputSelect({
							id : "endPlaceProvince",
							key : {
								id : "dictCode",
								name : "dictName",
								data : "data",
							},
							data : $scope.cache.provinces,
							simpleData : true,
							// 启用文本搜索
							// initData:[initProvice],
							searchAble : false,
							callback : function(id) {
								var id = id[0];
								$scope.search.endPlaceProvince = id;
								$scope.getCity('end', id);
							}
						});
					}, init_endPalceCity = function() {
						// 初始化下拉框
						inputSelect.dropCache();
						inputSelect({
							id : "endPalceCity",
							key : {
								id : "dictCode",
								name : "dictName",
								data : "data",
							},
							data : $scope.cache.endPlaceCity,
							simpleData : true,
							// 启用文本搜索
							// initData:[initProvice],
							searchAble : false,
							callback : function(id) {
								var id = id[0];
								$scope.search.endPalceCity = id;
							}
						});
					}, init_saleStatus = function() {
						// 初始化下拉框
						inputSelect.dropCache();
						inputSelect({
							id : "saleStatus",
							key : {
								id : "dictCode",
								name : "dictName",
								data : "data",
							},
							data : $scope.cache.saleStatus,
							simpleData : true,
							// 启用文本搜索
							// initData:[initProvice],
							searchAble : false,
							callback : function(id) {
								var id = id[0];
								$scope.search.saleStatus = id;
							}
						});
					};

					// 初始化下拉框
					inputSelect.dropCache();
					inputSelect({
						id : "productType",
						key : {
							id : "dictCode",
							name : "dictName",
							data : "data",
						},
						data : [ {
							"dictCode" : "self",
							"dictName" : "自营"
						}, {
							"dictCode" : "unself",
							"dictName" : "非自营"
						} ],
						simpleData : true,
						// 启用文本搜索
						// initData:[initProvice],
						searchAble : false,
						callback : function(id) {
							var id = id[0];
							$scope.search.productType = id;
						}
					});
					$("#departureDate").datetimepicker({
						// 设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
						language : "cn",
						// 输出格式化
						// format : 'yyyy-mm-dd hh:ii:ss',
						format : 'yyyy-mm-dd',
						// 直接选择‘今天’
						todayBtn : true,
						// 设置最精确的时间选择视图
						minView : 'month',
						// 高亮当天日期
						todayHighlight : true,
						// 显示“上午”“下午”
						showMeridian : true,
						// 选择完毕后自动关闭
						autoclose : true
					});

					/* 查询 end */
					$scope.renderGridFun = function() {
						if ($scope.cache.saleStatus.length > 0 && $scope.cache.types.length > 0) {
							$scope.grid = Support.init($scope.detailSupport, $scope.searchSupport);
						}
					}

				})
	}
});